package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.UserInfo;
import com.itheima.mapper.UserInfoMapper;
import com.itheima.service.db.UserInfoService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    //完善个人基本信息
    @Override
    public void save(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }

    //完善个人头像信息
    @Override
    public void update(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }

    //查询个人信息
    @Override
    public UserInfo findById(Long id) {
        return userInfoMapper.selectById(id);
    }

    //用户列表
    @Override
    public PageBeanVo findUserList(Integer pageNum, Integer pageSize) {

        IPage<UserInfo> page = new Page<>(pageNum,pageSize);

        QueryWrapper wrapper = new QueryWrapper();

        page = userInfoMapper.selectPage(page,wrapper);

        return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());
    }
    //更新用户信息
    @Override
    public void updateUserInfo(Integer userId, UserInfo userInfo) {
        UpdateWrapper<UserInfo> wrapper = new UpdateWrapper<>();
        wrapper.set("freezing_range", userInfo.getFreezingRange());
        wrapper.set("user_status", userInfo.getUserStatus());
        wrapper.eq("id", userId);
        userInfoMapper.update(userInfo, wrapper);
    }
}
